package zut.edu.cs.network.io.stream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileInputStreamDemo {

	public static void main(String[] args) {
		File file = new File("test.txt");
		byte[] content = null;
		try {
			FileInputStream file1 = new FileInputStream(file);
//			获取文件的大小，并作为数组的大小空间，避免了浪费
			content = new byte[file1.available()];
			file1.read(content);
			file1.close();
			System.out.println("读取完成！");
			
		} catch (FileNotFoundException e) {
			System.out.println("文件不存在！");
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("文件读取错误！");
			e.printStackTrace();
		}
		System.out.println(new String(content));

	}

}
